package com.nauu.atombuilder.figures;

import org.eclipse.draw2d.ImageFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.MouseEvent;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Color;

import com.nauu.atombuilder.AtomBuilderPlugin;

public class TextFieldFigure extends NodeFigure{
	
	public static final Dimension SIZE = new Dimension(195, 30);
	
//    private RectangleFigure rectangleFigure;
    private ImageFigure rectangleFigure;

    private Label label;

    public TextFieldFigure() {
//        this.rectangleFigure = new RectangleFigure();
        this.rectangleFigure = new ImageFigure(ImageDescriptor.createFromFile(AtomBuilderPlugin.class,"icons/textfield.png").createImage());
        this.label = new Label();
        this.add(rectangleFigure);
        this.add(label);
    }

    
	@Override
    public void setSize(int w, int h) {
    	super.setSize(SIZE);
    }
    
    public String getText() {
        return this.label.getText();
    }

    public Rectangle getTextBounds() {
        return this.label.getTextBounds();
    }

    public void setName(String name) {
        this.label.setText(name);
        this.repaint();
    }

    //------------------------------------------------------------------------
    // Overridden methods from Figure

    public void setBounds(Rectangle rect) {
        super.setBounds(rect);
        this.rectangleFigure.setBounds(rect);
        this.label.setBounds(rect);
    }

	public void translateToAbsolute(Dimension font) {
		this.rectangleFigure.translateToAbsolute(font);
	}

	@Override
	public void setBackgroundColor(Color color) {
		this.rectangleFigure.setBackgroundColor(color);
	}
	
	@Override
	public Dimension getPreferredSize(int wHint, int hHint) {
		return SIZE;
	}
	
}
